// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   GTSCalendarPatternImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;

import java.util.Calendar;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            PIVL_TSImpl, ANYImpl, BLImpl, CSImpl, 
//            GTSBase, IVL_TSImpl, PQImpl, TSImpl

public class GTSCalendarPatternImpl extends PIVL_TSImpl
{

    public static final String RCS_ID = "$Header: GTSCalendarPatternImpl.java 115.10 2005/05/13 15:03:38 atomlins noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: GTSCalendarPatternImpl.java 115.10 2005/05/13 15:03:38 atomlins noship $", "oracle.apps.ctb.hl7.types.common");
    CS _anchor;
    String _tsdigits;
    String _hull;
    INT _interleave;

    public static GTSCalendarPatternImpl valueOf(CS cs, String s, String s1, INT int1, BL bl)
    {
        return new GTSCalendarPatternImpl(cs, s, s1, int1, bl);
    }

    protected GTSCalendarPatternImpl(CS cs, String s, String s1, INT int1, BL bl)
    {
        _anchor = cs;
        _tsdigits = s;
        _hull = s1;
        _interleave = int1;
        _institutionSpecifiedTime = bl;
        init();
    }

    protected void init()
    {
        String s = _anchor.code().stringValue().toUpperCase();
        if(s.equals("J"))
        {
            Calendar calendar = Calendar.getInstance();
            calendar.clear();
            calendar.set(7, Integer.parseInt(_tsdigits));
            if(_hull != null)
            {
                Calendar calendar1 = (Calendar)calendar.clone();
                calendar1.set(7, Integer.parseInt(_hull));
                _phase = IVL_TSImpl.valueOf(TSImpl.valueOf(calendar.getTime()), BLImpl.TRUE, TSImpl.valueOf(calendar1.getTime()), BLImpl.TRUE);
            } else
            {
                com.sunwayhorizo.health.hl7.datatypes.TS ts = TSImpl.valueOf(calendar.getTime());
                _phase = IVL_TSImpl.valueOf(ts);
            }
            _period = PQImpl.valueOf(_interleave == null || _interleave.isNull().booleanValue() ? "1" : _interleave.toString(), "wk");
            _alignment = CSImpl.valueOf("DW");
            return;
        }
        String s1 = _tsdigits;
        if(!s.equals("Y"))
        {
            byte byte0 = 0;
            switch(s.charAt(0))
            {
            case 77: // 'M'
                byte0 = 4;
                break;

            case 68: // 'D'
                byte0 = 6;
                break;

            case 72: // 'H'
                byte0 = 8;
                break;

            case 78: // 'N'
                byte0 = 10;
                break;

            case 83: // 'S'
                byte0 = 12;
                break;
            }
            s1 = ((TSImpl)TSImpl.current()).literal().toString().substring(0, byte0) + _tsdigits;
        }
        try
        {
            com.sunwayhorizo.health.hl7.datatypes.TS ts1 = TSImpl.valueOf(s1);
            if(_hull != null && _hull.length() > 0)
            {
                String s2 = s1.substring(0, s1.length() - _hull.length()) + _hull;
                com.sunwayhorizo.health.hl7.datatypes.TS ts2 = TSImpl.valueOf(s2);
                _phase = IVL_TSImpl.valueOf(ts1, BLImpl.TRUE, ts2, BLImpl.TRUE);
            } else
            {
                _phase = IVL_TSImpl.valueOf(ts1);
            }
        }
        catch(Hl7Exception ctbexception)
        {
            RuntimeException runtimeexception = ANYImpl.newHullIVLException(s1, _hull);
            StringBuffer stringbuffer = new StringBuffer(runtimeexception.getMessage());
            stringbuffer.append("\nOriginating Stacktrace:\n");
            stringbuffer.append(ctbexception.toString());
            throw runtimeexception;
        }
        _alignment = TSImpl.twoLetter(_anchor);
        if(_interleave == null || _interleave.isNull().isTrue())
        {
            _period = PQImpl.valueOf("1", TSImpl.nextHigher(_anchor));
            return;
        } else
        {
            _period = PQImpl.valueOf(_interleave.toString(), TSImpl.calendarCycleUOM(_anchor));
            return;
        }
    }

    protected String generateLiteral()
    {
        StringBuffer stringbuffer = new StringBuffer(_anchor.toString());
        stringbuffer.append(_tsdigits);
        if(_hull != null)
        {
            stringbuffer.append("..");
            stringbuffer.append(_hull);
        }
        if(_interleave != null && _interleave.isNull().isFalse())
        {
            stringbuffer.append("/");
            stringbuffer.append(_interleave.toString());
        }
        if(_institutionSpecifiedTime.isTrue())
            stringbuffer.append("ist");
        return stringbuffer.toString();
    }

}
